package com.itWaiLong.Controller.User;

import com.itWaiLong.Dao.Entities.DeleteProject;
import com.itWaiLong.Dao.personal_project;
import com.itWaiLong.Result.Result;
import com.itWaiLong.ReturnString.ResponseData;
import com.itWaiLong.Service.PersonalProjectService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/PProject")
public class PersonalProjectController {

    @Autowired
    private PersonalProjectService pService;

    /**
     * 添加用户的个人项目
     * @param pProject 项目信息
     * @return 返回项目的添加状态
     */
    @PostMapping("/AddProject")
    public Result AddProject(@RequestBody personal_project pProject) {
        log.info("添加项目:{}", pProject);

        pService.AddProject(pProject);
        return Result.success();
    }

    /**
     * 删除用户个人项目
     * @param pProject
     * @return
     */
    @PostMapping("/deleteProject")
    public Result DeleteProject(@RequestBody DeleteProject pProject) {
        log.info("删除用户个人项目的数据{}", pProject);

        pService.deleteProject(pProject);

        return Result.success();
    }

    /**
     * 编辑项目
     * @param pProject
     * @return
     */
    @PostMapping("/updateProject")
    public Result updateProject(@RequestBody personal_project pProject) {
        log.info("编辑项目信息：{}", pProject);
        pService.updateProject(pProject);
        return Result.success();
    }

    /**
     * 查看个人所有项目信息
     * @return
     */
    @GetMapping("/getAllProject")
    public Result<List<personal_project>> getAllProject() {
        List<personal_project> list = pService.selectAllProject();
        return Result.success(list);
    }

    /**
     * 通过项目名称查找项目
     * @param projectName
     * @return
     */
    @GetMapping("/selectProjectByName")
    public Result selectProjectByName(@RequestParam String projectName) {
        log.info("项目名称：{}", projectName);

        personal_project personalProject = pService.selectProjectByName(projectName);
        return Result.success(personalProject);
    }

    /**
     * 通过项目id查找用户项目
     * @param projectId
     * @return
     */
    @GetMapping("/selectProjectById")
    public Result selectProjectById(@RequestParam int projectId) {
        log.info("项目id：{}", projectId);
        personal_project personalProject = pService.selectProjectById(projectId);
        return Result.success(personalProject);
    }
}
